/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.CargoDAO;
import model.ProfissaoDAO;
import model.Profissional;
import model.ProfissionalDAO;

/**
 *
 * @author Eduarda
 */
public class TrataAlterarCadastro extends Comando{

    @Override
    public void executar(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, IOException, ServletException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            response.setContentType("text/html");
            
            
            String login = request.getParameter("login");
            
            Profissional prof = new ProfissionalDAO().pesquisarLogin(login);
            ProfissaoDAO pacdao = new ProfissaoDAO();
            CargoDAO profc = new CargoDAO(); 
            HttpSession session = request.getSession(false);
            session.setAttribute("profissional", prof);
            
            session.setAttribute("listaProfissoes", pacdao.pesquisar());
            session.setAttribute("listaCargos", profc.pesquisar());
            //Redireciona para outra página
            response.sendRedirect("editarCadastro.jsp");
        } catch (IOException ioex) {
            throw new ServletException(ioex);
        } catch(SQLException sqlex){
              throw new ServletException (sqlex);
        }
    }
    
}
